﻿@using Moments.Service
@using Moments.Model
@inject ConfigService ConfigService
@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider 

<MCard Class="mx-auto ma-5" Width="350" Outlined>
    <MCardTitle>
        Moments Admin 👋
    </MCardTitle>
    <MCardSubtitle>
        <MTextField Label="密钥" @bind-Value="_passWord" Outlined></MTextField>
        <MButton Color="orange lighten-2" OnClick="Submit">登录</MButton>
    </MCardSubtitle>
</MCard>

@code {
    string? _passWord;

    async Task Submit()
    {
        if (ConfigService.Get("Token") == _passWord)
        {
            var token = new UserSession
            {
                Token = _passWord,
                Role = "Admin"
            };
            await CustomAuthenticationStateProvider.Login(token);
        }
        else
        {
            AdminLayout.PushSnackbars(AlertTypes.Error, "密钥错误！");
        }
    }

}